#pragma once
#include <string>
#include "XType.h"
#include "cocos2d.h"

using namespace cocos2d;
using std::string;

namespace LTGame
{
	typedef struct __color{
		unsigned char r;
		unsigned char g;
		unsigned char b;
		unsigned char a;
	}LTCOLOR;

	class  Tools
	{
	public :
		static bool isPointInRect(int x, int y, int x1, int y1, int x2, int y2);
		static bool isPointInRect(int X, int Y, short* rect);

		static int isPointAtLeftRight(int x1, int y1, int x2, int y2, int x, int y);
		static bool isTwoLineIntersect(int x1, int y1, int x2, int y2, int m1, int n1, int m2, int n2);
		static bool isLineColWidthRect(int x1, int y1, int x2, int y2, int left, int top, int right, int bottom);

		static XPoint<int>* getPoint_TwoLineIntersect(int x1, int y1, int x2, int y2, int m1, int n1, int m2, int n2);
		static XPoint<int>* getPoint_LineColWidthRect(int x1, int y1, int x2, int y2, int left, int top, int right, int bottom);

		static bool isRectIntersect(short* rect0, short* rect1);
		static bool isRectIntersect(int, int, int, int, int, int, int, int);
		static bool isContain(int* rect, int* r);
		static bool contains(int rx, int ry, int rw, int rh, int X, int Y, int W, int H);

		static int adjustData(int data, int minVal, int maxVal);

		static bool isEmpty(short* r);
		static void translate(short* r, int dx, int dy);
		static int getDistance(int dx, int dy);
		static int getDistance(int x1, int y1, int x2, int y2);
		static bool getEquationRoot(float a, float b, float c, float* ans_1, float* ans_2);

		static int exponent(int exp, int num);
		static bool isInArray(int * a,int len ,int v);
		static int readFromByteArray(byte* data, int arr_len, int offset, int length);
		static bool Int_Compare(int value0 , int operate , int value1);
		
		static CCLabelTTF* drawString(CCLayer* layer,const char * str,const char *fontName,float x, float y, float fontSize,const CCPoint& anchor = CCPoint(0.5,0.5));
		static void drawRect(CCRect* rt, bool closePolygon, bool fill, LTCOLOR* color);
		static void fillRect(int x,int y,int width,int height);
		static int getNumDigit(int num);
		static void fillRect2();

		static ccV3F_C4B_T2F_Quad  setModule( float x,float y,float w, float h, float sx, float sy,CCTexture2D* ptext2d,int flix,LTCOLOR* color);
		static ccV3F_C4B_T2F_Quad  setModule( float x,float y,float w, float h, float sx, float sy,CCTexture2D* ptext2d,int flix,LTCOLOR* color,float rw,float rh);

		template<class T>
		static void Init2Null(T** a, unsigned int size){
			if(a == NULL){
				return;
			}
			for (unsigned int i = 0; i < size; ++i ){
				a[i] = NULL;
			}
		}
	};

}